<?php
/**
 * @file
 * Retreives the list of friends already using an application.
 *
 * Usage:
 *  - A page that wants to retreive the list of friends already using an
 *    application should include/require this page once and only once.
 *
 * Parameter(s):
 *  - None.
 *
 * Global variable(s) set:
 *  - $exclude_friends_str : A comma-separated list of friends already using the
 *                           application.
 *
 * Global variable(s) unset:
 *  - None.
 *
 * Exception(s):
 *  - None.
 *
 * This file includes/requires:
 *  - None.
 */

// global variable(s) ==========================================================
//!< Comma-separated list of friends already using the application.
$exclude_friends_str = "";


// implementation ==============================================================
// create facebook object
require_once $PATH_COMMON . "php/fb_facebook.php";
try {
  // get users already using the application
  $exclude_friends_str = $fb->api_client->friends_getAppUsers();
  if (1 < count($exclude_friends_str)) {
    $exclude_friends_str = implode(",", $exclude_friends_str);
  }
} catch (Exception $ex) {
  // canvas user had not authorized application
  // do nothing
  /* too slow
  // get list of friends
  $uids_friends = $fb->api_client->friends_get();
  // test each friend individually
  foreach ($uids_friends as $uid_friend) {
    // test if friend already using application
    if (true == $fb->api_client->users_isAppUser($uid_friend)) {
      // add to exclude list
      $exclude_friends_str .= "," . $uid_friend;
    }
  }
  if (0 != strlen($exclude_friends_str)) {
    // remove first comma
    $exclude_friends_str = substr($exclude_friends_str, 1);
  }
  //*/
}
?>
